home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / smailsrc.zip / SMAIL.ZIP / LMAIL.C < prev    next >
Text File  |  1990-05-05  |  2KB  |  74 lines

  1. /*
  2.  *  lmail: local mail delivery agent
  3.  *
  4.  *  Stephen Trier
  5.  *  January 12, 1990
  6.  *
  7.  *  Version 1.0   1/12/90  "cat" command.  Uses binary mode for I/O.  Need
  8.  *     a sensible way to handle ^Z.  Uses standard MS-DOS wildcard filespecs.
  9.  *
  10.  *  Version 1.1   3/27/90  Convert from "cat" into "lmail".  Complete
  11.  *     rewrite.  This version is fast, but may thrash if several recipients
  12.  *     are specified on the command line.
  13.  *
  14.  *  This program is in the public domain.
  15.  *
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include <pwd.h>
  22. #include "config.h"
  23.  
  24. #define BUFLEN      80   /* Size of buffer to use when copying     */
  25. #define MAXFILES    40   /* MS-DOS command line can hold 128 chars */
  26.  
  27. char buf[BUFLEN];
  28. FILE *fp[MAXFILES];
  29.  
  30. /*
  31.  *   Configuration code
  32.  */
  33.  
  34. #define RCVAR(A)    ((A == 0) ? "UUPCSYSRC" : "UUPCUSRRC")
  35.  
  36. char *ms_maildir = "\\usr\\mail",
  37.      *ms_passwd = NULL;
  38.  
  39. static struct table_entry table[] = {
  40.     "passwd", &ms_passwd,
  41.     "maildir", &ms_maildir,
  42.     NULL
  43.     } ;
  44.  
  45. /*
  46.  *      Main routine here.  Shotgun-style copying to mail directories.
  47.  */
  48.  
  49. int main(int argc, char *argv[])
  50. {
  51.     char mailbox[80];
  52.     int i, j, errlevel = 0;
  53.  
  54.     ms_config(table);
  55.     pw_openfile(ms_passwd);  /* Defaults to NULL, or default file */
  56.  
  57.     for (j = 0, i = 1; i < argc; i++)
  58.     if (getpwnam(argv[i]) != NULL)  {
  59.         sprintf(mailbox, "%s/%s", ms_maildir, argv[i]);
  60.         fp[j++] = fopen(mailbox, "a");
  61.         }
  62.     else  {
  63.         errlevel = 1;
  64.         fprintf(stderr, "lmail: user \"%s\" unknown.\n", argv[i]);
  65.         }
  66.  
  67.     while (fgets(buf, BUFLEN, stdin) != NULL)
  68.     for (i = 0; i < j; i++)
  69.         fputs(buf, fp[i]);
  70.  
  71.     return errlevel;
  72. }
  73.  
  74.